from rest_framework import serializers
from .models import *


# 商家的序列化器
class MerchantSer(serializers.ModelSerializer):
    class Meta:
        model = Merchant
        fields = "__all__"


# 菜品分类的序列化器
class DishesClassifySer(serializers.ModelSerializer):
    mer_name = serializers.SerializerMethodField()
    def get_mer_name(self,obj):
       return obj.merchant_id.username
    class Meta:
        model = DishesClassify
        fields = "__all__"


# 收货地址的序列化器
class AddressSer(serializers.ModelSerializer):
    user_name = serializers.SerializerMethodField()
    def get_user_name(self,obj):
       return obj.user_id.username
    class Meta:
        model = Address
        fields = "__all__"


# 优惠券的序列化器
class CouponSer(serializers.ModelSerializer):
    class Meta:
        model = Coupon
        fields = "__all__"


# 菜的序列化器
class DishesSer(serializers.ModelSerializer):
    class Meta:
        model = Dishes
        fields = "__all__"


# 用户的序列化器
class UserSer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"